package org.jsbd.boss.action;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang.StringUtils;
import org.jsbd.boss.common.DataGridModel;
import org.jsbd.boss.common.ResponseUtils;
import org.jsbd.boss.domian.channel.AddReserveConfigVo;
import org.jsbd.boss.service.IReserveAddConfigService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/reserveAddConfig")
public class ReserveAddConfigController {

	@Resource
	private IReserveAddConfigService addConfigService;

	@RequestMapping(value = "/list")
	@ResponseBody
	public Map<String, Object> list(DataGridModel model, String mark) {
		Map<String, Object> map = new HashMap<String, Object>();
		if (StringUtils.isNotBlank(mark)) {
			List<AddReserveConfigVo> configList = addConfigService.selectConfigList(mark);
			map.put("rows", configList);
		}
		return map;
	}

	@RequestMapping(value = "/list", method = RequestMethod.GET)
	public String list(HttpServletResponse response) {
		return "reserveAddConfig/configList";
	}

	@RequestMapping(value = "/save")
	public void saveRetent(@RequestBody AddReserveConfigVo[] list, HttpServletResponse response) {

		addConfigService.saveConfig(Arrays.asList(list));

		ResponseUtils.responseSuccess(response);
	}

	@RequestMapping(value = "/delete")
	public void deleteRetent(@RequestBody AddReserveConfigVo form, HttpServletResponse response) {

		addConfigService.deleteConfig(form.getId());

		ResponseUtils.responseSuccess(response);
	}

}
